# 请参阅 https://aka.ms/customizecontainer 以了解如何自定义调试容器，以及 Visual Studio 如何使用此 Dockerfile 生成映像以更快地进行调试。

# 此阶段用于在快速模式(默认为调试配置)下从 VS 运行时
FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS base
USER $APP_UID
WORKDIR /app
EXPOSE 8080
EXPOSE 8081


# 此阶段用于生成服务项目
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["Directory.Build.props", "."]
COPY ["Directory.Build.targets", "."]
COPY ["modules/AdminModule/EasyDDD.AdminModule.Host.WebAPI/EasyDDD.AdminModule.Host.WebAPI.csproj", "modules/AdminModule/EasyDDD.AdminModule.Host.WebAPI/"]
COPY ["frameworks/EasyDDD.Host.WebAPI/EasyDDD.Host.WebAPI.csproj", "frameworks/EasyDDD.Host.WebAPI/"]
COPY ["frameworks/EasyDDD.Application/EasyDDD.Application.csproj", "frameworks/EasyDDD.Application/"]
COPY ["frameworks/EasyDDD.Domain/EasyDDD.Domain.csproj", "frameworks/EasyDDD.Domain/"]
COPY ["frameworks/EasyDDD/EasyDDD.csproj", "frameworks/EasyDDD/"]
COPY ["frameworks/EasyDDD.Infrastructure.EFCore.Records/EasyDDD.Infrastructure.EFCore.Records.csproj", "frameworks/EasyDDD.Infrastructure.EFCore.Records/"]
COPY ["frameworks/EasyDDD.Infrastructure/EasyDDD.Infrastructure.csproj", "frameworks/EasyDDD.Infrastructure/"]
COPY ["frameworks/EasyDDD.Infrastructure.EFCore.Repository/EasyDDD.Infrastructure.EFCore.Repository.csproj", "frameworks/EasyDDD.Infrastructure.EFCore.Repository/"]
COPY ["frameworks/EasyDDD.ServiceDefaults/EasyDDD.ServiceDefaults.csproj", "frameworks/EasyDDD.ServiceDefaults/"]
COPY ["modules/AdminModule/EasyDDD.AdminModule.Host.WebAPI.Controllers/EasyDDD.AdminModule.Host.WebAPI.Controllers.csproj", "modules/AdminModule/EasyDDD.AdminModule.Host.WebAPI.Controllers/"]
COPY ["modules/AdminModule/EasyDDD.AdminModule.Application/EasyDDD.AdminModule.Application.csproj", "modules/AdminModule/EasyDDD.AdminModule.Application/"]
COPY ["modules/EasyDDD.Module.IntegrationEvents.Shared/EasyDDD.Module.IntegrationEvents.Shared.csproj", "modules/EasyDDD.Module.IntegrationEvents.Shared/"]
COPY ["modules/AdminModule/EasyDDD.AdminModule.Records/EasyDDD.AdminModule.Records.csproj", "modules/AdminModule/EasyDDD.AdminModule.Records/"]
COPY ["frameworks/EasyDDD.Infrastructure.EFCore.Records.PostgreSql/EasyDDD.Infrastructure.EFCore.Records.PostgreSql.csproj", "frameworks/EasyDDD.Infrastructure.EFCore.Records.PostgreSql/"]
COPY ["modules/AdminModule/EasyDDD.AdminModule/EasyDDD.AdminModule.csproj", "modules/AdminModule/EasyDDD.AdminModule/"]
COPY ["modules/AdminModule/EasyDDD.AdminModule.Repository/EasyDDD.AdminModule.Repository.csproj", "modules/AdminModule/EasyDDD.AdminModule.Repository/"]
COPY ["frameworks/EasyDDD.Infrastructure.EFCore.Repository.PostgreSql/EasyDDD.Infrastructure.EFCore.Repository.PostgreSql.csproj", "frameworks/EasyDDD.Infrastructure.EFCore.Repository.PostgreSql/"]
COPY ["modules/AdminModule/EasyDDD.AdminModule.Domain/EasyDDD.AdminModule.Domain.csproj", "modules/AdminModule/EasyDDD.AdminModule.Domain/"]
COPY ["frameworks/EasyDDD.Domain.User/EasyDDD.Domain.User.csproj", "frameworks/EasyDDD.Domain.User/"]
RUN dotnet restore "./modules/AdminModule/EasyDDD.AdminModule.Host.WebAPI/EasyDDD.AdminModule.Host.WebAPI.csproj"
COPY . .
WORKDIR "/src/modules/AdminModule/EasyDDD.AdminModule.Host.WebAPI"
RUN dotnet build "./EasyDDD.AdminModule.Host.WebAPI.csproj" -c $BUILD_CONFIGURATION -o /app/build

# 此阶段用于发布要复制到最终阶段的服务项目
FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./EasyDDD.AdminModule.Host.WebAPI.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

# 此阶段在生产中使用，或在常规模式下从 VS 运行时使用(在不使用调试配置时为默认值)
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "EasyDDD.AdminModule.Host.WebAPI.dll"]